import Vue from 'vue';
import FastClick from 'fastclick';
import VueRouter from 'vue-router';
import App from './App';
import router from './router';
import store from './store';
import {
  Tabbar,
  TabbarItem,
  Group,
  Cell,
  Tab,
  TabItem,
  Flexbox,
  FlexboxItem,
  Swiper,
  SwiperItem,
  XCircle,
  Loading ,
  InlineLoading ,
  XImg ,
  XSwitch
} from 'vux';

// import "vue-material-design-icons/styles.css";
import './styles/styles.less';
Vue.use(VueRouter);

// 统一注册Icon
const requireComponent = require.context('./components/icons', false, /[a-zA-Z]\w+\.vue$/);
const regex = /[a-z][A-Z]/g;
requireComponent.keys().forEach(fileName => {
  const componentConfig = requireComponent(fileName);
  let fName = componentConfig.default.name;
  let newName = fName;
  fName.match(regex).forEach(str => {
    newName = newName.replace(str, `${str[0]}-${str[1]}`);
  })
  Vue.component(
    newName.toLowerCase(),
    componentConfig.default || componentConfig
  )
})

Vue.component('tabbar', Tabbar);
Vue.component('tabbar-item', TabbarItem);
Vue.component('tab', Tab);
Vue.component('tab-item', TabItem);
Vue.component('group', Group);
Vue.component('cell', Cell);
// Vue.component('flexbox', Flexbox);
// Vue.component('flexbox-item', FlexboxItem);
Vue.component('swiper', Swiper);
Vue.component('swiper-item', SwiperItem);
Vue.component('x-circle', XCircle);
Vue.component('loading', Loading);
Vue.component('inline-loading ', InlineLoading );
Vue.component('x-img ', XImg );
Vue.component('x-switch ', XSwitch );
// Vue.component('search', Search)
FastClick.attach(document.body);

Vue.config.productionTip = false;

const HeroType = {
  '1': '坦克',
  '2': '战士',
  '3': '刺客',
  '4': '法师',
  '5': '射手',
  '6': '辅助',
};

const InsProp = {
  physicalAttack: '物理攻击',
  spellAttack: '法术攻击',
  physicalDefense: '物理防御',
  spellDefense: '法术防御',
  maxHealth: '最大生命值',
  criticalStrike: '暴击率',
  criticalEffect: '暴击效果',
  attackSpeed: '攻击速度',
  moveSpeed: '移动速度',
  physicalArmor: '物理护甲穿透',
  spellArmor: '法术护甲穿透',
  physicalRevive: '物理吸血',
  spellRevive: '法术吸血',
  fivesecRevive: '5秒回血',
  coolDown: '冷却缩减',
  physicalAttack2: '物理攻击2',
  spellAttack2: '法术攻击2',
  maxHealth2: '生命2'
};

window.InsProp = InsProp;

const SkillType = {
  '0': '被动',
  '1': '主升',
  '2': '副升',
  '3': '有大点大',
  '4': '无升级',
};
Vue.filter('HeroType', (val) => {
  return HeroType[val];
});
Vue.filter('SkillType', (val) => {
  return SkillType[val];
});
Vue.filter('InsProp', (val) => {
  return InsProp[val];
});
document.addEventListener('DOMContentLoaded', () => {
  const $Vue = new Vue({
    router,
    store, // 注入到所有子组件
    components: {
      App
    }
  })
  router.onReady(() => {
    $Vue.$mount('#app-box')
  })
  window.$Vue = $Vue
})
